package com.guigu.youxuan.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.youxuan.common.utils.PageUtils;
import com.guigu.youxuan.pojo.SupplierInfo;
import com.guigu.youxuan.service.ISupplierInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liweixin
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/supplierInfo")
public class SupplierInfoController {

    @Autowired
    private ISupplierInfoService supplierInfoService;

    /**
     * 供应商查询所有
     * @param pageNo
     * @param pageSize
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/queryAll/{pageNo}/{pageSize}")
    @ResponseBody
    public PageInfo<SupplierInfo> page(@PathVariable int pageNo,
                                       @PathVariable int pageSize,
                                       @RequestBody SupplierInfo supplierInfo) {
        PageInfo<SupplierInfo> pageInfo=this.supplierInfoService.getSupplierList(pageNo,pageSize,
                supplierInfo);
        System.out.println("pageInfo = " + pageInfo);
        return pageInfo;
    }

    /**
     *获取id
     * @param
     * @return
     */
    @RequestMapping("/getById/{supplierId}")
    @ResponseBody
    public SupplierInfo getById(int merchantId) {
        SupplierInfo supplierInfo = supplierInfoService.getById(merchantId);
        return supplierInfo;
    }

    /**
     * 修改
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/updById")
    @ResponseBody
    public String updById(@RequestBody SupplierInfo supplierInfo) {
        boolean flag = supplierInfoService.updateById(supplierInfo);
        if (flag) {
            return "ok";
        }
        return "error";
    }

    /**
     *删除获取id
     * @param supplierInfo
     * @return
     */
    @RequestMapping("delBySupplierId")
    @ResponseBody
    public String delBackUser(@RequestBody SupplierInfo supplierInfo) {
        supplierInfoService.delBySupplierId(supplierInfo);
        return "删除成功！";
    }

    /**
     *条件查询
     * @param supplierInfo
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/supplierInfoPage/{pageNo}/{pageSize}")
    @ResponseBody
    public PageUtils<SupplierInfo> supplierInfoFuHePage(
            @RequestBody SupplierInfo supplierInfo,
            @PathVariable int pageNo,
            @PathVariable int pageSize) {
        PageUtils<SupplierInfo> page = this.supplierInfoService.supplierInfoFuHePage(supplierInfo,pageNo, pageSize);
        return page;
    }


    /**
     * 复核成功
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/supplierInfoFuHeOk")
    @ResponseBody
    public String storageCellReviewPassed(@RequestBody SupplierInfo supplierInfo) {
        supplierInfo.setCheckTag("S001-3");
        boolean flag = supplierInfoService.updateById(supplierInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }
    /**
     * 复核成功
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/supplierInfoFuHeNoOk")
    @ResponseBody
    public String storageCellNoReviewPassed(@RequestBody SupplierInfo supplierInfo) {
        supplierInfo.setCheckTag("S001-2");
        boolean flag = supplierInfoService.updateById(supplierInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }
    /**
     * 供应商资料维护带所登录的用户id查询供应商数据
     * @param sysUsersId
     * @return
     */
    @RequestMapping("/SupplierDataPage/{sysUsersId}")
    @ResponseBody
    public SupplierInfo SupplierDataPage(@PathVariable int sysUsersId) {
        SupplierInfo page= this.supplierInfoService.getByIdform(sysUsersId);
        return page;
    }

    /**
     * 供应商入驻 添加
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/supplierInfoAdd/{id}")
    @ResponseBody
    public String supplierInfoAdd(@RequestBody SupplierInfo supplierInfo, @PathVariable int id) {
        supplierInfo.setSysUsersId(id);
        supplierInfo.setCheckTag("S001-1");
        boolean flag = supplierInfoService.save(supplierInfo);
        if (flag) {
            return "correct";
        }
        return "error";
    }
    /**
     * 对供应商信息修改
     * @param supplierInfo
     * @return
     */
    @RequestMapping("/supplierUpdate")
    @ResponseBody
    public String supplierUpdate(@RequestBody SupplierInfo supplierInfo){
        boolean flag=this.supplierInfoService.updateById(supplierInfo);
        if (flag){
            return "ok";
        }
        return "error";
    }
}
